
{assign var="modelPlural" value=$modelClass|pluralize}
{include file="include/header.tpl" title="Browse `$modelPlural`"}

{include file="smutty/modelRelated.tpl" model=""}

{if $total > $perPage}
<p>
<b>Pages:</b>

{php}

function drawPagelinks( $smarty ) {

	$smarty->depend( 'function', 'link' );
	$modelClass = $smarty->get_template_vars( 'modelClass' );
	$total = $smarty->get_template_vars( 'total' );
	$perPage = $smarty->get_template_vars( 'perPage' );
	$start = $smarty->get_template_vars( 'start' );

	$pages = 10;
	$first = round(( $start - ($perPage*($pages/2)) ) / $perPage) + 1; // first link to show
	if ( $first < 1 ) $first = 1;
	$max = round( $total / $perPage );
	if ( $max > $pages ) $max = $pages;
	$curr = round( $start / $perPage ) + 1;
	$last = round($total/$perPage);

	if ( $first > 1 ) {
		smarty_function_link(array(
			url => array(
				action => 'modelBrowse',
				smutty_modelClass => $modelClass
			),
			text => '1'
		), $smarty );
		echo ( $first > 2 ) ? ' ... ' : ' ';
	}

	if ( $first + $max > $last )
		$first = $last - $max + 1;

	for ( $page=$first; ($page<($first+$max)) && ($page<=$last); $page++ ) {
		smarty_function_link(array(
			url => array(
				action => 'modelBrowse',
				smutty_modelClass => $modelClass,
				start => ($page - 1) * $perPage
			),
			text => $page,
			'class' => $page == $curr ? 'current' : ''
		), $smarty );
		echo ' ';
	}

	if ( $first+$pages <= $total/$perPage ) {
		echo ( $last > $first+$pages ) ? ' ... ' : ' ';
		smarty_function_link(array(
			url => array(
				action => 'modelBrowse',
				smutty_modelClass => $modelClass,
				start => $total - $perPage
			),
			text => $last
		), $smarty );
	}

}

drawPageLinks( $this );

{/php}
</p>
{/if}

<table>
	<tr>
		<th class="link"></th>
		{foreach item="field" from=$fields}
			<th>{$field->name|escape}</th>
		{/foreach}
	</tr>
	{foreach item="model" from=$models}
	<tr>
		<td class="link">
			<a href="{url action="modelShow" smutty_modelClass=$modelClass smutty_modelId=$model->id }" title="View Record"><img
				src="{url action="resource" folder="icons" file="show.png" }" /></a>
			<a href="{url action="modelEdit" smutty_modelClass=$modelClass smutty_modelId=$model->id }" title="Edit Record"><img
				src="{url action="resource" folder="icons" file="edit.png" }" /></a>
		</td>
		{foreach item="field" from=$fields}
			{assign var="name" value=$field->name}
			{assign var="value" value=$model->$name}
			<td>
				{if is_object($value)}
					{link url={ action="modelShow" smutty_modelClass=$name smutty_modelId=$value->id } text=$value->name }
				{else}
					{$model->$name|escape|truncate:"30"}
				{/if}
			</td>
		{/foreach}
	</tr>
	{/foreach}
</table>

{include file="include/footer.tpl"}
